#include "qlineserieswidget.h"
#include<QtCharts/QChartView>
#include<QtCharts/QLineSeries>
#include<QDebug>

QLineSeriesWidget::QLineSeriesWidget(QWidget *parent)
    : QMainWindow{parent}
{

}

void QLineSeriesWidget::paintEvent(QPaintEvent *event)
{
    // 折线图的形式显示数据
    QLineSeries* pSeries = new QLineSeries();
    // 显示点
    pSeries->setPointsVisible(true);
    // 是否显示点坐标
    pSeries->setPointLabelsVisible(true);

    pSeries->append(0,6);
    pSeries->append(2,4);
    pSeries->append(3,8);
    pSeries->append(7,4);
    pSeries->append(10,5);

    *pSeries << QPointF(11,1)<<QPointF(13,3)<<QPointF(17, 6) << QPointF(18, 3) << QPointF(20, 2);

    qDebug() << pSeries->type();
    QChart* pChart = new QChart();
    // 返回图表中图例对象
    pChart->legend()->hide();

    pChart->addSeries(pSeries);
    // 创建图表轴
    pChart->createDefaultAxes();
    pChart->setTitle("简单折线图示例");

    QChartView* pChartView = new QChartView(pChart);
    pChartView->setRenderHints(QPainter::Antialiasing);
    setCentralWidget(pChartView);

}
